package com.tjp.subject.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.tjp.subject.common.enums.IsDeletedFlagEnum;
import com.tjp.subject.domain.convert.SubjectCategoryConverter;
import com.tjp.subject.domain.entity.SubjectCategoryBO;
import com.tjp.subject.domain.service.SubjectCategoryDomainService;
import com.tjp.subject.infra.basic.entity.SubjectCategory;
import com.tjp.subject.infra.basic.service.SubjectCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: jz-club
 * @description: 领域层分类接口实现
 * @author: aaronTang
 * @create: 2024-02-22
 */
@Service
@Slf4j
public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainService {

    @Autowired
    private SubjectCategoryService subjectCategoryService;

    public void insert(SubjectCategoryBO subjectCategoryBO) {

        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.boToEntity(subjectCategoryBO);

        SubjectCategory insert = subjectCategoryService.insert(subjectCategory);

    }

    public List<SubjectCategoryBO> queryCategory(SubjectCategoryBO subjectCategoryBO) {

        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.convertBOToCategoryEntity(subjectCategoryBO);

        List<SubjectCategory> subjectCategories = subjectCategoryService.queryCategory(subjectCategory);
        List<SubjectCategoryBO> subjectCategoryBOList = SubjectCategoryConverter.INSTANCE.entityToBOList(subjectCategories);

        if (log.isInfoEnabled()) {
            log.info("SubjectCategoryDomainServiceImpl.subjectCategoryBOList: {}", JSON.toJSONString(subjectCategoryBOList));
        }
        return subjectCategoryBOList;
    }

    public int update(SubjectCategoryBO subjectCategoryBO) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.boToEntity(subjectCategoryBO);

        int update = subjectCategoryService.update(subjectCategory);
        return update;
    }

    public int delete(SubjectCategoryBO subjectCategoryBO) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.boToEntity(subjectCategoryBO);
        subjectCategory.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());

        int update = subjectCategoryService.update(subjectCategory);
        return update;
    }





}
